package trip;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
import javax.persistence.ManyToOne;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
import javax.persistence.UniqueConstraint;
import javax.persistence.Id;

@Entity
@Table(name = "PERSON_TRIP",
		uniqueConstraints = @UniqueConstraint(columnNames={"person_id", "trip_id"}))
public class Person_trip{
	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private long id;
	
	@ManyToOne(cascade = CascadeType.DETACH)
	@JoinColumn(name = "person_id") 
	private Person person;
	
	@ManyToOne(cascade = CascadeType.DETACH)
	@JoinColumn(name = "trip_id") 
	private Trip trip;
	
	@ManyToOne(cascade = CascadeType.DETACH)
	@JoinColumn(name = "departure_stop_id") 
	private Stop departure_stop;

	@ManyToOne(cascade = CascadeType.DETACH)
	@JoinColumn(name = "arrival_stop_id") 
	private Stop arrival_stop;

	//constructors
	public Person_trip() {};
		
	public Person_trip(long id, Person person, Trip trip, Stop departure_stop, Stop arrival_stop) {
			this.id = id;
			this.person = person;
			this.trip = trip; 
			this.departure_stop = departure_stop;
			this.arrival_stop = arrival_stop;
	}
	
	//id
	public long getId() {
		return id;
	}

	public Person_trip setId(long id) {
		this.id = id;
		return this;
	}
		
	//person
	public Person getPerson() {
		return person;
	}

	public Person_trip setPerson(Person person) {
		this.person = person; 
		return this;
	}

	//trip
	public Trip getTrip() {
		return trip;
	}

	public Person_trip setTrip(Trip trip) {
		this.trip = trip; 
		return this;
	}

	//departure_stop
	public Stop getDeparture_stop() {
		return departure_stop;
	}
	
	public Person_trip setDeparture_stop(Stop departure_stop) {
		this.departure_stop = departure_stop;
		return this;
	}

	//arrival_stop
	public Stop getArrival_stop() {
		return arrival_stop;
	}
	
	public Person_trip setArrival_stop(Stop arrival_stop) {
		this.arrival_stop = arrival_stop;
		return this;
	}
	
	public boolean equals(Person_trip pt) {
		if (pt == null)
			return false;
		if (this.id == pt.id && 
			this.person.equals(pt.person) &&
			this.trip.equals(pt.trip) &&
			this.departure_stop.equals(pt.departure_stop) &&
			this.arrival_stop.equals(pt.arrival_stop))
			return true;
		else
			return false;
	}
}	